package com.example.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.example.enums.SysPayStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

@Data
@TableName(value = "sys_pay")
public class SysPay {

    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    //订单编号
    @TableField(value = "order_id")
    private String orderId;

    //支付方式
    @TableField(value = "type")
    private String type;

    //支付金额
    @TableField(value = "amount")
    private String amount;

    //支付标题
    @TableField(value = "title")
    private String title;

    //支付附言
    @TableField(value = "attach")
    private String attach;

    //支付状态
    @TableField(value = "payed")
    private boolean payed = false;

    //推送状态
    @TableField(value = "status")
    private String status = SysPayStatus.INIT;

    //错误信息
    @TableField(value = "error")
    private String error;

    //账号id
    @TableField(value = "user_id")
    private Long userId;

    //openId
    @TableField(value = "open_id")
    private String openId;

    //尝试次数
    @TableField(value = "retry_count")
    private int retryCount = 0;

    //充实时间
    @TableField(value = "retry_time")
    private Date retryTime;

    //支付时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "pay_time")
    private Date payTime;

    //创建日期
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time")
    private Date createTime;

    //更新日期
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time")
    private Date updateTime;

    public void recalculateFields() {
        if (this.createTime == null) {
            this.createTime = new Date();
        }
        if (this.updateTime == null) {
            this.updateTime = new Date();
        }
    }
}
